package com.rrqs.activity.adapter;

import java.util.List;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.rrqs.activity.OrderDetailNewActivity;
import com.zadtek.xmqishi.R;
import com.rrqs.activity.data.OrderWaitItemData;

public class OrderWaitItemAdapter extends CommonAdapter<OrderWaitItemData> {
	private String mainid;
	public OrderWaitItemAdapter(Context context, List<OrderWaitItemData> datas,
			int layoutId,String mainid) {
		super(context, datas, layoutId);
		// TODO Auto-generated constructor stub
		this.mainid =mainid;
	}

	@SuppressLint("ResourceAsColor")
	@Override
	public void convert(ViewHolders holder, final OrderWaitItemData t,int position) {
		ImageView newtask_order_img = holder.getView(R.id.waitgood_order_img);
		TextView newtask_goods_name = holder.getView(R.id.waitgood_goods_name);
		TextView newtask_goods_address = holder
				.getView(R.id.waitgood_goods_address);
		TextView newtask_goods_distance = holder
				.getView(R.id.waitgood_goods_distance);
		TextView getfood = holder.getView(R.id.getfood);
		LinearLayout itemlayout =holder.getView(R.id.itemlayout);
		
		newtask_goods_name.setText(t.getSite_name());
		newtask_goods_address.setText(t.getSite_addr());
		newtask_goods_distance.setText(t.getLocation()+"km");
		//2,配送中（确认送达），4.已送达，3.已取消，1未取货
				//状态改为 1：配送中，2：未取货，3：取消中，4：已送达，5：已取消
		if (t.getStatus().equals("11")) {
			newtask_goods_distance.setText("已取消");
			getfood.setVisibility(View.GONE);
			newtask_order_img.setImageResource(R.drawable.getgoods1);
			newtask_goods_name.setTextColor(mContext.getResources().getColor(
					R.color.newtask1));
			newtask_goods_distance.setTextColor(mContext.getResources()
					.getColor(R.color.newtask1));
		} else if (t.getStatus().equals("7")) {
			newtask_goods_distance.setText("已取货");
			getfood.setVisibility(View.GONE);
			newtask_goods_name.setTextColor(mContext.getResources().getColor(
					R.color.newtask1));
			newtask_goods_distance.setTextColor(mContext.getResources()
					.getColor(R.color.newtask1));
			newtask_order_img.setImageResource(R.drawable.getgoods1);
		} else {
			newtask_goods_distance.setText(t.getLocation()+"km");
			getfood.setVisibility(View.VISIBLE);
			newtask_order_img.setImageResource(R.drawable.getgoods);
			newtask_goods_name.setTextColor(mContext.getResources().getColor(
					R.color.newtask));
			newtask_goods_distance.setTextColor(mContext.getResources()
					.getColor(R.color.single_money));
		}
		
		itemlayout.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				if (mainid !=null && !mainid.equals("")) {
				Intent intent = new Intent(mContext, OrderDetailNewActivity.class);
				intent.putExtra("mainid", mainid);
				intent.putExtra("status", "wait");
				mContext.startActivity(intent);
				}
			}
		});
	}

}
